/// Regex Util.
class RegexUtil {
  /// Regex of simple mobile.
  static const String regexMobileSimple = '^[1]\\d{10}\$';

  /// Regex of email.
  static const String regexEmail =
      '^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*\$';

  /// Regex of url.
  static const String regexUrl = '[a-zA-Z]+://[^\\s]*';

  /// must contain numbers
  /// 必须包含数字,
  static const String regexNumbers = '(?=.*?[0-9])';
  /// 必须包含字母,
  static const String regexLetter = '(?=.*?[A-Za-z])';
  ///只能包含数字或者字母
  static const String regexNumbersLetter = '^[A-Za-z0-9]+\$';

  static const String regexNumber = '[0-9]+([.]{1}[0-9]+){0,1}';

  static final Map<String, String> cityMap = Map();

  ///Return whether input matches regex of simple mobile.
  static bool isMobileSimple(String input) {
    return matches(regexMobileSimple, input);
  }

  /// Return whether input matches regex of email.
  static bool isEmail(String input) {
    return matches(regexEmail, input);
  }

  /// Return whether input matches regex of url.
  static bool isURL(String input) {
    return matches(regexUrl, input);
  }

  static bool hasNumber(String input) {
    return matches(regexNumbers, input);
  }

  static bool hasLetter(String input) {
    return matches(regexLetter, input);
  }

  static bool isNumberLetter(String input) {
    return matches(regexNumbersLetter, input);
  }

  static String? extractNumbers(String input) {
    if (input.isEmpty) return null;
    return RegExp(regexNumber).stringMatch(input);
  }

  static bool matches(String regex, String input) {
    if (input.isEmpty) return false;
    return RegExp(regex).hasMatch(input);
  }
}
